package com.huluobo.a2307douyindemo.search

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SearchView
import androidx.recyclerview.widget.GridLayoutManager
import com.huluobo.a2307douyindemo.R
import com.huluobo.a2307douyindemo.adapter.HomeAdapter
import com.huluobo.a2307douyindemo.databinding.FragmentSearchCaptionBinding
import com.huluobo.lib_base.mvvm.BaseFragment


class SearchCaptionFragment : BaseFragment<FragmentSearchCaptionBinding, SearchViewModel>() {
    private lateinit var homeAdapter: HomeAdapter
    override fun initData() {
        vm.getSearchSuccess.observe(this) {
            homeAdapter.data.clear()
            //sortedBy 需要有内容来接收,不是直接排序
            homeAdapter.data.addAll(it.sortedByDescending { it.caption })
            homeAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.searchRv.layoutManager = GridLayoutManager(requireContext(), 2)
        homeAdapter = HomeAdapter()
        binding.searchRv.adapter = homeAdapter
    }
}